import { ActionBase } from "./ActionBase";

/**
 * 行为队列
 */
export class ActionQueue {

    private _actions: ActionBase[] = [];
    private _currentAction: ActionBase = null;
    private _pause: boolean = false;

    public addAction(action: ActionBase) {
        this._actions.push(action);
    }

    public removeAction(action: ActionBase) {
        let index = this._actions.indexOf(action);
        if (index >= 0) {
            this._actions.splice(index, 1);
        }
    }

    public update(dt: number) {
        if (this._pause || this._currentAction || this._actions.length <= 0) {
            return;
        }
        this._currentAction = this._actions.shift();
        this._currentAction.doAction();
    }

    public setPause(isPause: boolean) {
        this._pause = isPause;
    }
}